package paper.xml;

import java.io.*;
import java.util.*;

import paper.bayes.PDF;


class PaperSetHash implements PaperSet {

    class Paper 
    {
        String name;
        String[] authors = new String[0];
        String where;
        int id;
        int date = -1;
        int year = -1;
        int stPage=-1,endPage=-1;
        int volume = -1;
        int numAuthors;
    }

    Vector<Paper> papers;
    Paper  current;
    PDF authors;
    PDF wheres;
    PDF titles;
    PDF affiliations;
    int numParsed=0;

    PaperSetHash()
    {
        papers = new Vector<Paper>();
        current = new Paper();
        authors = new PDF();
        titles = new PDF();
        wheres = new PDF();
        affiliations = new PDF();
    }
    
    public void setCurrentId(int x) {
        current.id = x;
    }
    
    public void setCurrentName(String x) {
        current.name = x;
    }

    public void setCurrentStPage(int x) {
        current.stPage = x;
    }

    public void setCurrentEndPage(int x) {
        current.endPage = x;
    }

    public void setCurrentYear(int x) {
        current.year = x;
    }

    public void setCurrentVolume(int x) {
        current.volume = x;
    }

    public void setCurrentDate(int x) {
        current.date = x;
    }

    public void setCurrentWhere(String x) {
        current.where = x;
    }

    public void finalise(Vector<Integer> cites, Vector<Integer> citedBy,
                         Vector<String> auths) {
        for (int i=0; i<auths.size(); i++) {
            authors.add(auths.elementAt(i));
        }
        if (current.name != null) {
            titles.add(current.name);
        }
        if (current.where != null) {
            System.out.println(current.where);
            wheres.add(current.where);
        }
//        affiliations.add(current.affiliation);
        if( numParsed++ % 10000 == 0)
            System.err.println("Parsed " + numParsed);
        current = new Paper();
    }

    void dumpHash() throws java.io.IOException
    {
        authors.done();
        titles.done();
        wheres.done();
        authors.save(new File("authors"));
        titles.save(new File("titles"));
        wheres.save(new File("wheres"));
    }
}
